package com.dd.admin.business.pay;

import cn.hutool.core.bean.BeanUtil;
import com.dd.admin.business.member.domain.MemberDto;
import com.dd.admin.business.member.entity.Member;
import com.dd.admin.business.pay.domain.BuildCardSell;
import com.dd.admin.business.pay.domain.ChargedCardSell;
import com.dd.admin.business.pay.domain.MemberProductSell;
import com.dd.admin.business.pay.service.PayService;
import com.dd.admin.business.sell.entity.Sell;
import com.dd.admin.common.aop.operationLog.aop.OperLog;
import com.dd.admin.common.aop.operationLog.aop.OperType;
import com.dd.admin.common.model.result.ResultBean;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@Api(tags = "结算控制器")
@RestController
public class PayController {

    @Autowired
    PayService payService;

    @ApiOperation(value = "开卡结算")
    @ApiOperationSupport(order = 3)
    @PostMapping("/pay/buildCard")
    @Transactional
    @OperLog(operModule = "开卡结算",operType = OperType.ADD,operDesc = "开卡结算")
    public ResultBean<Sell> buildCard(@RequestBody @Validated BuildCardSell buildCardSell) {
        Sell sell = payService.executeBuildCard(buildCardSell);
        return ResultBean.success(sell);
    }

    @ApiOperation(value = "续卡结算")
    @ApiOperationSupport(order = 3)
    @PostMapping("/pay/chargedCard")
    @Transactional
    @OperLog(operModule = "续卡结算",operType = OperType.ADD,operDesc = "续卡结算")
    public ResultBean<Sell> chargedCard(@RequestBody @Validated ChargedCardSell chargedCardSell) {
        Sell sell = payService.executeChargedCard(chargedCardSell);
        return ResultBean.success(sell);
    }

    @ApiOperation(value = "商品结算")
    @ApiOperationSupport(order = 3)
    @PostMapping("/pay/productPay")
    @Transactional
    @OperLog(operModule = "商品结算",operType = OperType.ADD,operDesc = "商品结算")
    public ResultBean<Sell> buildCard(@RequestBody @Validated MemberProductSell productSell) {
        Sell sell = payService.executeProduct(productSell);
        return ResultBean.success(sell);
    }


}
